
#if 0


#define _CRT_SECURE_NO_WARNINGS
 
#include "Den_CLog.h"
#include <signal.h>
#include <iostream>
#include <string>
#include <list>

 namespace
 {
     void Reaction_for_Crash(int signalnum);
     void fnExit(void) {  puts ("Procedure of terminate process"); }

     void Intercept_crash_state()
     {
        atexit(fnExit); 
        signal(SIGABRT,Reaction_for_Crash); signal(SIGSEGV,Reaction_for_Crash);
        signal(SIGILL,Reaction_for_Crash); signal(SIGFPE,Reaction_for_Crash);
          
        #ifndef _MSC_VER
             signal(SIGBUS,  handle); 
        #endif
     }
 }// namespace


namespace Den{
//-------------
struct LogFrame;
struct LogNode
{
    LogNode(const char* text): mData(GetData()), mText(text), mFrame(0l)    { std::cout<<"LogNode(): text\n"; }
    LogNode(LogFrame* frame): mData(GetData()),  mText(""),   mFrame(frame) { std::cout<<"LogNode(): frame\n"; }
    std::string GetData()const{return "data: "; }
    void View()const
    {
        std::cout<< mData;
        if(mFrame!=0l){ std::cout<<"FRAME\n"; }
        else std::cout<<mText<<std::endl;
    }
private:
    std::string mText, mData; LogFrame* mFrame;
};

struct LogFrame
{
    LogFrame(std::ostringstream* stream, LogFrame* owner, const char* func, const size_t deep)
        :mStream(stream),mOwner(owner), mFunc(func), mDeep(deep) {  }

    void EndText()
    {
        if(mStream==0l || mStream->str().size()==0) return;
        LogNode node(mStream->str().c_str()); mNodes.push_back(node); mStream->clear();
    }
    void Add(LogFrame& frame){ EndText(); LogNode node(&frame); mNodes.push_back(node); }
    LogFrame* GetOwner(){ return mOwner; }
    const std::list<LogNode>& GetNodes()const { return mNodes; }

    void View()const
    {
        const std::string tabs(mDeep*Log::eTAB_SIZE, ' ');
        std::cout<< tabs;
        std::list<LogNode>::const_iterator it = mNodes.begin();
        while(it!=mNodes.end()) { std::cout<< tabs; (*it).View(); ++it; }
    }
private:
    std::string GetData()const{return "data: "; }
private:
    std::list<LogNode> mNodes;
    LogFrame* mOwner; std::string mFunc; size_t mDeep;  std::ostringstream* mStream;
};

struct LogCore
{
    LogCore():mCur(0l),mDeep(0)
    {
        Intercept_crash_state();
        LogFrame first_frame(0l, 0l, "starting logger", mDeep);
        mFrames.push_back(first_frame);
    }
    void Enter(std::ostringstream* ptr, const char* func)
    {
        LogFrame& prev = mFrames.back(); ++mDeep; LogFrame frame(ptr, &prev, func, mDeep);
        mFrames.push_back(frame);
        mCur = &mFrames.back(); 
        prev.Add(frame);
    }
    void LogCore::Exit()
    {
        EndText();
        mCur = mFrames.back().GetOwner(); --mDeep;
    }

    void Flush()const
    {
        std::cout<<"LogCore::Flush()\n";
        View();
    }
    
    void EndText()
    {
        if(mCur==0l) { std::cout<<"nul\n"; return;}
        mCur->EndText(); 
    }

    void View()const
    {
        std::list<LogFrame>::const_iterator it = mFrames.begin();
        while(it!=mFrames.end()){(*it).View();  ++it;}
    }
private:
    std::list<LogFrame> mFrames; LogFrame* mCur; size_t mDeep; 
};
//-------------
}//namespace Den

 namespace
 {
     Den::LogCore gCore;
     void Reaction_for_Crash(int signalnum)
     {
         std::cout<<"Crash_intercept!\n";
         gCore.Flush();
         signal(signalnum, SIG_DFL);  
         exit(3); 
     }
 }

//typedef boost::function<Any(Any, const std::vector<Any>&)> Method;
//template<class T, class R, class A0, class A1>
//Method makeMethod(R (T::*methodPtr)(A0, A1))
//{
//  typedef R (T::*MethodPtr)(A0, A1);
//  struct MethodImpl
//  {
//    MethodImpl(MethodPtr methodPtr) :
//      methodPtr(methodPtr)  
//    {}
//
//    Any operator(Any obj, const std::vector<Any>& args)
//    {
//      T* realObj = boost::any_cast<T*>(obj);
//      A0 a0 = boost::any_cast<A0>(args.at(0));
//      A1 a1 = boost::any_cast<A1>(args.at(1));
//      (realObj->*methodPtr)(a0, a1);
//    }
//    MethodPtr methodPtr;
//  };
//  return MethodImpl(methodPtr);
//}

namespace Den{

   LogCore& Log::sCore = gCore;
   Log::~Log(){ std::cout<<"~Log(): end\n";sCore.Exit(); }
   Log::Log(const char* funcName, const char* file, const size_t line)
   { 
       std::cout<<"Log(): begin\n"; sCore.Enter(&mStream, funcName); 
   }
   void Log::Flush()const{ sCore.Flush();   }
   void Log::EndText()   { sCore.EndText(); }
//-------------------------------------------------------------------
}//namespace Den

#endif